<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-10-31
 * Time: 15:13
 */

namespace app\domain;


use app\src\base\helper\ConfigHelper;
use app\src\customer\logic\CustomerInfoLogic;
use app\src\user\action\QueryAction;
use app\src\user\logic\MemberConfigLogic;

class CustomerDomain extends BaseDomain
{
    /**
     * 所有客服信息
     * @author hebidu <email:346551990@qq.com>
     */
    public function all(){


        //客服列表数据
        $info = [
            [
                'group_name'=>lang('pre_sale_customer_service'),
                'list'=>[
//                    ['alibaichuan_uid'=>'TE1121477896392','uid'=>112, 'nickname'=>'小小受红','is_online'=>'1','desc'=>'全天在线'],
//                    ['alibaichuan_uid'=>'TE1131477898709','uid'=>113, 'nickname'=>'小王小王小王','is_online'=>'1','desc'=>'工作日在线'],
                ]
            ],
            [
                'group_name'=>lang("after_sale_customer_service"),
                'list'=>[
//                    ['alibaichuan_uid'=>'TE1141477898730','uid'=>114, 'nickname'=>'小绿(售后客服)','is_online'=>'1','desc'=>'天天在线'],
//                    ['alibaichuan_uid'=>'TE1151477898747','uid'=>115, 'nickname'=>'小受小受小受小受小受(售后客服)','is_online'=>'0','desc'=>'全天在线']
                ]
            ]
        ];

        $user_group_id = 6;//售前客服
        $result = (new QueryAction())->queryCustomer($user_group_id);

        if($result['status']){
            $list = [];
            foreach ($result['info'] as $vo){
                array_push($list,[
                    'avatar'=>ConfigHelper::getAvatarUrl($vo['uid']).'&r='.time(),
                    'alibaichuan_uid'=>$vo['alibaichuan_uid'],
                    'uid'=>$vo['uid'],
                    'nickname'=>$vo['nickname'],
                    'is_online'=>1,
                    'desc'=>''
                ]);
            }

            $info[0]['list'] = $list;
        }

        $user_group_id = 7;//售后客服
        $result = (new QueryAction())->queryCustomer($user_group_id);

        if($result['status']){
            $list = [];
            foreach ($result['info'] as $vo){
                array_push($list,[
                    'avatar'=>ConfigHelper::getAvatarUrl($vo['uid']).'&r='.time(),
                    'alibaichuan_uid'=>$vo['alibaichuan_uid'],
                    'uid'=>$vo['uid'],
                    'nickname'=>$vo['nickname'],
                    'is_online'=>1,
                    'desc'=>''
                ]);
            }

            $info[1]['list'] = $list;
        }

        $this->apiReturnSuc($info);
    }

    public function lastContact(){
        $uid = $this->_post('uid',0);
        $to_uid = $this->_post('to_uid',0);
        $msg = $this->_post('msg','');
        $map = ['uid'=>$uid, 'msg'=>$msg,'to_uid'=>$to_uid];
        $result = (new CustomerInfoLogic())->addNew($map);
        $this->returnResult($result);
    }
}